/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */


package org.rails.extjs.calendar;

import org.rails.extjs.Option;
import org.rails.extjs.data.Store;
import org.rails.extjs.javascript.JavaScript;
import org.rails.extjs.panel.Panel;

public class CalendarPanel extends Panel {

	public CalendarPanel() {
		super();
	}

	public CalendarPanel(Option configOptions) {
		super(configOptions);
	}

	public CalendarPanel(String title) {
		super(title);
	}

	public CalendarPanel(String id, String title) {
		super(id, title);
	}
	
	public void setEventStore(Store eventStore){
		addOption("eventStore",eventStore);
	}
	
	public Store getEventStore(){
		return (Store) getOption("eventStore");
	}
	
	public void setCalendarStore(Store calendarStore){
		addOption("calendarStore",calendarStore);
	}
	
	public Store getCalendarStore(){
		return (Store)getOption("calendarStore");
	}
	
	public void setMonthViewCfg(Boolean showHeader,Boolean showWeekLinks,
			Boolean showWeekNumbers){
		final Option monthViewCfg = new Option();
		monthViewCfg.put("showHeader", showHeader);
		monthViewCfg.put("showWeekLinks", showWeekLinks);
		monthViewCfg.put("showWeekNumbers", showWeekNumbers);
		addOption("monthViewCfg",monthViewCfg);
	}
	
	public Option getMonthViewCfg(){
		return (Option) getOption("monthViewCfg");
	}
	
	public void setLayoutConfig(Option layoutConfig){
		addOption("layoutConfig", layoutConfig);
	}
	
	public Option getLayoutConfig(){
		return (Option) getOption("layoutConfig");
	}
	
	public void setShowDayView(Boolean showDayView){
		addOption("showDayView",showDayView);
	}
	
	public Boolean isShowDayView(){
		return getBoolean("showDayView",true);
	}
	
	public void setShowWeekView(Boolean showWeekView){
		addOption("showWeekView",showWeekView);
	}
	
	public Boolean isShowWeekView(){
		return getBoolean("showWeekView",true);
	}
	
	public void setShowMonthView(Boolean showMonthView){
		addOption("showMonthView",showMonthView);
	}
	
	public Boolean isShowMonthView(){
		return getBoolean("showMonthView",true);
	}
	
	public void setShowNavBar(Boolean showNavBar){
		addOption("showNavBar",showNavBar);
	}
	
	public Boolean isShowNavBar(){
		return getBoolean("showNavBar",true);
	}
	
	public void setTodayText(String todayText){
		addOption("todayText",todayText);
	}
	
	public String getTodayText(){
		return getString("todayText","Today");
	}
	
	public void setShowTodayText(Boolean showTodayText){
		addOption("showTodayText",showTodayText);
	}
	
	public Boolean isShowTodayText(){
		return getBoolean("showTodayText",true);
	}
	
	public void setShowTime(Boolean showTime){
		addOption("showTime",showTime);
	}
	
	public Boolean isShowTime(){
		return getBoolean("showTime",true);
	}
	
	public void setDayText(String dayText){
		addOption("dayText",dayText);
	}
	
	public String getDayText(){
		return getString("dayText","Day");
	}
	
	public void setWeekText(String weekText){
		addOption("weekText",weekText);
	}
	
	public String getWeekText(){
		return getString("weekText","Week");
	}
	
	public void setMonthText(String monthText){
		addOption("monthText",monthText);
	}
	
	public String getMonthText(){
		return getString("monthText","Month");
	}
	
	public void setStartDate(Long startDate){
		addOption("startDate",new JavaScript("new Date("+startDate+")"));
	}
	
	public JavaScript getStartDate(){
		return (JavaScript) getOption("startDate");
	}
	
	@Override
	public String getScript() {
		script = new StringBuffer("");
		createItems();
		script.append("new Ext.calendar.CalendarPanel(");
		script.append(createOptions());
		script.append(")");
		return script.toString();
	}

}
